home *** CD-ROM | disk | FTP | other *** search
/ Acorn Risc Technologies StrongARM CD-ROM / Acorn Risc Technologies StrongARM CD-ROM.iso / ftp / documents / appnotes / 001_015 / 004c / Text
Encoding:
Text File  |  1994-08-04  |  59.3 KB  |  1,371 lines

  1. -----------------------------------------------------------------------------
  2. 16th June 1992
  3. -----------------------------------------------------------------------------
  4. Support Group Application Note
  5. Number: 004
  6. Issue: 1
  7. Author:
  8. -----------------------------------------------------------------------------
  9.  
  10. Tube Application Note
  11.  
  12. -----------------------------------------------------------------------------
  13. Applicable Hardware: BBC B
  14.                      BBC B+
  15.                      BBC Master 128
  16.  
  17. Related Application Notes:
  18.  
  19.  
  20. -----------------------------------------------------------------------------
  21. Copyright (C) Acorn Computers Limited 1992
  22.  
  23. Every effort has been made to ensure that the information in this leaflet is 
  24. true and correct at the time of printing. However, the products described in
  25. this leaflet are subject to continuous development and improvements and
  26. Acorn Computers Limited reserves the right to change its specifications at
  27. any time. Acorn Computers Limited cannot accept liability for any loss or
  28. damage arising from the use of any information or particulars in this
  29. leaflet. ACORN, ECONET and ARCHIMEDES are trademarks of Acorn Computers
  30. Limited.
  31. -----------------------------------------------------------------------------
  32. Support Group
  33. Acorn Computers Limited
  34. Acorn House
  35. Vision Park
  36. Histon
  37. Cambridge       CB4 4AE                                          
  38. -----------------------------------------------------------------------------
  39.  
  40. Overview
  41.  
  42. One of the BBC Microcomputer's strengths lies in its sophisticated Operating
  43. System, the MOS. This operating system has a very fast and flexible response
  44. to Interrupts, which allows the machine to take a wide range of peripherals
  45. and handle them with ease. The TUBE is a fast bus interface through which
  46. additional Co-processors (also called second processors) can be added. When
  47. a co-processor is connected to the TUBE interface, the BBC Micro continues
  48. to look after all of the I/O processing, whilst the additional co-processor
  49. now carries out the task of running the Language Application.
  50.  
  51. The Co-Processor
  52.  
  53. The co-processor can be based on any microprocessor chip, and can have any
  54. memory size that this chip can address. Units already in existence include
  55. 64K RAM 6502, 1MBit 32016, 64K Z80 etc. You may wonder why there is any
  56. point in adding a unit using a 6502 chip, the same series as the BBC Micro
  57. itself, and with a RAM  size the same as the Model B+?  The reasons are
  58. twofold:
  59.  
  60. 1)  Speed - whilst the co-processor is carrying out the computational tasks
  61. of the Application  program, the BBC Micro itself can look after the screen
  62. display, printer, disc drive etc.
  63.  
  64. 2)  Memory - In the Model B or B+ with a Disc Filing System, the position of
  65. PAGE is typically &1900.  The application has to fit above this and below
  66. HIMEM.  In the Model B, HIMEM moves down when a high resolution screen
  67. display is selected further reducing the memory available. In the 6502
  68. co-processor, PAGE is typically at &800 and HIMEM is at &8000 regardless of
  69. Filing System and screen display mode.
  70.  
  71. The TUBE interface
  72.  
  73. The co-processor is connected to the TUBE connector on the BBC Micro via the
  74. TUBE cable.  In the system, the BBC Micro is referred to as the "host", and
  75. the co-processor as the "parasite". Within any co-processor there is a
  76. custom chip, the TUBE ULA, which provides the actual communicating interface
  77. between both processors. The processors are not synchronised with one
  78. another, and the ULA chip forms an effective set of pigeon holes through
  79. which each processor can leave information for the other to read when it is
  80. ready.
  81.  
  82. For the TUBE interface to work, there has to be a set of machine code in
  83. both processors which looks after the communicating protocols on both sides
  84. of the ULA. In the BBC Micro, this "host" code resides typically in one of
  85. the sideways ROM's ie NFS 3.34, DNFS, 1770 DFS etc. In the co-processor, the
  86. "parasite" code resides in a small ROM commonly called the "boot" ROM.
  87.  
  88. Software Compatibility
  89.  
  90. Applications software which has been written for the BBC Micro itself may
  91. not run on a 6502 co-processor if it has not followed the rules for using
  92. the Tube interface.  applications writers may become over familiar with the
  93. memory map in the BBC Micro and it's operating system interface and "bypass"
  94. the standard routines. This application will then almost certainly fail when
  95. it is run in the different memory map of a cop-processor and where not all
  96. of the assumed interfaces are available. In the following sections of the
  97. Application Note, the various "legal" way of interfacing with the operating
  98. system will be described. If properly implemented, the Application Program
  99. will then run in either the BBC Micro or the 6502 co-processor, with no
  100. modification.  If the communication techniques across the Tube interface are
  101. also properly implemented then maximum advantage of the overall system speed
  102. can be obtained without one processor waiting an unreasonable length of time
  103. fo the other processor to respond.
  104.  
  105. The Load address used by filing system file names contains a "high order"
  106. address which indicates which processor memory map it is to be loaded into. 
  107. For example, a load address of &FFFFxxxx indicates that the file should be
  108. loaded into the I/O processor area.  A load address of &0000xxxx indicates
  109. that the parasite is the destination.  In practice, filing systems shorten
  110. the high order bytes to two ie &FFxxxx or &00xxxx.  A file loaded under
  111. BASIC control will load into the current language processor regardless of
  112. the file load address.  This ability to force *LOADing of files into a
  113. particular processor can be used to set up user machine code from a filing
  114. system into the I/O processor when the co-processor is in use.
  115.  
  116. The TUBE ULA
  117.  
  118. As stated previously, the ULA acts as a parallel interface between two
  119. asynchronous processor systems. It consists of four byte-wide read-only
  120. registers and four byte-wide write-only registers.  Eight bytes of memory
  121. mapped I/O space are used to address these registers, four for the data
  122. registers and four for the associated status registers.
  123.  
  124. Register number 1
  125.  
  126.         I/O address     Co-proc address
  127. status  &FEE0           &FEF8           write/read (clears IRQ) 
  128. data    &FEE1           &FEF9           bit 7 - data available/IRQ
  129.                                         bit 6 - not full
  130.  
  131. Parasite to Host:  Carries the OSWRCH call. Data register is a FIFO that can
  132. handle a VDU command length (10 bytes).
  133.  
  134. Host to Parasite:  There is a 1 byte buffer. It is used to generate IRQ's in
  135. the parasite from events in the host.
  136.  
  137.  
  138. Register number 2
  139.  
  140.         I/O address     Co-proc address
  141. status  &FEE2           &FEFA           write/read 
  142. data    &FEE3           &FEFB           bit 7 - data available
  143.                                         bit 6 - not full
  144.  
  145. Used to implement OS calls that take a long time or that cannot interrupt
  146. Host tasks.  The parasite passes a byte describing the required task. The
  147. two processors then exchange data  until the task is complete.  OS calls
  148. handled through this register include:  OSRDCH, OSCLI, OSBYTE, OSWORD,
  149. OSBPUT, OSBGET, OSFIND, OSARGS, OSFILE, OSGBPB.
  150.  
  151. Register number 3
  152.  
  153.         I/O address     Co-proc address
  154. status  &FEE4           &FEFC           write/read 
  155. data    &FEE5           &FEFD           bit 7 - data available/NMI
  156.                                         bit 6 - not full
  157.  
  158. Used for the background task of fast data transfer between the two
  159. processors.
  160.  
  161.  
  162. Register number 4
  163.  
  164.         I/O address     Co-proc address
  165. status  &FEE6           &FEFE           write (sets IRQ)/read (clears IRQ)
  166. data    &FEE7           &FEFF           bit 7 - data available/IRQ
  167.                                         bit 6 - not full/IRQ
  168.  
  169. Used as the control channel for block transfers going through Register 3,
  170. and also the transfer register for error strings from host to parasite. In
  171. both cases, the host interrupts the parasite by placing a byte into the
  172. Register.  In the former case it is a byte describing the required action,
  173. in the latter it is an error code.
  174.  
  175. Writing for compatibility
  176.  
  177. The applications software writer needs to know which operating system
  178. interfaces will work "across the tube", and which will not. He will also
  179. need to know how to implement other techniques for those that don't work.
  180.  
  181. Valid calls across the Tube:  OSWRCH, OSBYTE (Y only returned for A>= &80),
  182. OSRDCH, OSCLI, OSWORD, OSBPUT, OSBGET, OSFIND, OSFILE, OSARGS, OSGBPB.
  183.  
  184. Note:
  185. a)  OSBYTE calls have some restrictions in the co-processor ie:
  186.       &00-&7F - Only X (not Y) is sent and returned.
  187.       &82 - Always returns 00 in both X and Y (ie the parasite high order
  188. address).
  189.       &83 - Always returns 00 in X and 08 in Y (ie OSHWM in parasite).
  190.       &84 - Always returns &8000 or &B800 (ie the position of HIMEM in the
  191. parasite).
  192.  
  193. b)  OSWORD call parameters sent and received across the Tube can be
  194. ascertained from the following table
  195.         OSWORD No.      Params sent             Params received
  196.         1   (&01)               0               5
  197.         2   (&02)               5               0
  198.         3   (&03)               0               5
  199.         4   (&04)               5               0
  200.         5   (&05)               2               5
  201.         6   (&06)               5               0
  202.         7   (&07)               8               0
  203.         8   (&08)               14              0
  204.         9   (&09)               4               5
  205.         10 (&0A)                1               9
  206.         11 (&0B)                1               5
  207.         12 (&0C)                5               0
  208.         13 (&0D)                0               8
  209.         14 (&0E)                16              16
  210.         15 (&0F)                16              16
  211.         16 (&10)                16              13
  212.         17 (&11)                13              13
  213.         18 (&12)                0               128
  214.         19 (&13)                8               8
  215.         20 (&14)                128             128
  216.         <128 (&80)              16              16
  217.         >127 (&7F)              XY offset 0             XY offset 1 (ie in param block)
  218. Invalid calls across the Tube:  OSRDRM/OSRDSC, OSWRSC
  219.  
  220. Other invalid actions include:
  221.   Peeking/Poking memory unless the location is guaranteed to be the same in
  222. both memory maps. 
  223.   Directly addressing memory mapped I/O locations such as VIA.  
  224.   Directly addressing &F4, the ROM latch variable.  
  225.   Keeping data areas in &A00, &B00 and &C00. These are above PAGE in the
  226. parasite. 
  227.   Using pages 4, 5, 6 and 7 in the I/O processor, normally reserved for the
  228. current language.  These are used by the Tube code.
  229.   Using the two pages above normal PAGE position in the I/O processor. These
  230. are used for font explosion when a parasite processor is being used.
  231. Therefore stay above &2100, if PAGE is normally &1900, for user machine
  232. code.
  233.  
  234. Valid communicating techniques:
  235. OSBYTE 146 - Read from FRED (1MHz bus).
  236. OSBYTE 147 - Write to FRED (1MHz bus).
  237. OSBYTE 148 - Read from JIM (IMHz bus).
  238. OSBYTE 149 - Write to JIM (1MHz bus).
  239. OSBYTE 150 - Read from SHEILA  (memory mapped I/O).
  240. OSBYTE 151 - Write to SHEILA (memory mapped I/O).
  241. OSBYTE 157 - Fast Tube BPUT.
  242. OSBYTE 234 - Read Tube presence.
  243. OSWORD 5 - Read from I/O processor (transfers 1 byte).
  244. OSWORD 6 - Write to I/O processor (transfers 1 byte).
  245. OSWORD 224 to 225 - Passed through USERV vector (Can transfer up to 128
  246. bytes either way across the Tube).
  247.  
  248. Some typical examples:
  249.  
  250. a) Moving a few bytes:  Use OSWORD 5 or 6 from the co-processor the
  251. appropriate number of times.
  252.  
  253. b) Moving up to 128 bytes:  OSWORD 5 or 6 is typically too slow for more
  254. than a few bytes, hence the following is a recommended approach for
  255. the transfers to or from the co-processor and initiated by the co-processor:
  256.  
  257. Use OSWORDS in the range &E0(224) to &FF(255).  These "unknown" OSWORDS are
  258. passed through the USERV vector at &200 in the I/O processor.  Thus to
  259. transfer 64 bytes from the co-processor to the I/O processor we select, say
  260. OSWORD &E0, with the following parameter block:
  261.         XY + 0   68     bytes to transmit
  262.              1    0     bytes to receive
  263.              2   LO     Lo byte of destination in I/O processor
  264.              3   HI     Hi byte of destination in I/O processor
  265.              4    x     1st byte of 64
  266.              |    |     |
  267.             68    x     64th byte of 64
  268.  
  269.  
  270. To transmit 64 bytes from the I/O processor to the co-processor, we select,
  271. say OSWORD &E1, with the following parameter block:
  272.  
  273.  
  274.         XY + 0    4     bytes to transmit
  275.              1   68     bytes to receive
  276.              2   LO     Lo byte of source location in I/O processor
  277.              3   HI     Hi byte of source location in I/O processor
  278.  
  279. In practice you would intercept the USERV vector in the I/O processor (at
  280. &200,1) for the first run of the program. When &E0 is intercepted, the data
  281. from the parameter block already set up is ready to be moved across the Tube
  282. by the co-processor Tube code into the I/O processor location given in the
  283. parameter block.  Control is returned to the program.  When &E1 is
  284. intercepted, the data is taken from the address given in the parameter block
  285. and placed in the parameter block starting at address offset 4.  Following
  286. this, the Tube code will copy the data across the Tube into the co-processor
  287. into the original parameter block location.
  288.  
  289. c) Moving large quantities of data:  To move large quantities of data, for
  290. example a complete screen update, the fast Tube BPUT OSBYTE call is used. 
  291. Prior to the call, some machine code is placed in the I/O processor ready to
  292. handle the data as it arrives across the Tube from the co-processor.  When
  293. data is ready to be moved across the Tube, an OSBYTE &9D (157) is made to
  294. initiate the users code to in the I/O processor.  The data is moved through
  295. Tube register 1 and handled by the user code on the other side.  Note that
  296. all OSBYTE calls are vectored through the BYTEV vector at &20A,B in the I/O
  297. processor, and this vector has to be intercepted to detect an OSBYTE &9D
  298. call and pick up the X and Y parameters to be used by the user's code.  The
  299. advantage of OSBYTE &9D over other OSBYTE calls is that after the X and Y
  300. parameters have been sent across the Tube, control is immediately returned
  301. to the parasite.  no parameters are returned.
  302.  
  303.  
  304.  
  305. The Correct Use of Tubes
  306.  
  307. The Tube (c)Acorn Computers etc. is both a custom chip and a set of
  308. protocols. The protocols control the flow of control and data between a
  309. second processor and the BBC machine to which it is attached.  Clearly the
  310. implementation of these protocols in the second processor is different with
  311. different processors and operating environments, so this document is not
  312. concerned with second processor code.  This document does however please
  313. constraints on the performance of second processors, as the description of
  314. the Tube use on the BBC machine side includes expected response times so
  315. that the BBC machine user need not poll the hardware.
  316.  
  317. Conventions.
  318.  
  319. We assume you know about the 6502, and a bit about BBC machines. Hexadecimal
  320. numbers are written &<Hex digit> (<Hex digit>^) eg &FEE5, &0406.  Decimal
  321. numbers are just written.  Host means BBC computer, parasite means  second
  322. processor.
  323.  
  324. 1.  Claiming the Tube
  325.  
  326. Before you can use the Tube, you must claim it successfully. This is to
  327. prevent reentrancy problems with background and foreground tasks trying to
  328. use the system at the same time, for instance during an Econet (c) peek.  Of
  329. course, before attempting to use the Tube system you must be certain that
  330. the Tube is present, by using OSBYTE call &EA with Y=&FF, X=0.  The answer,
  331. in X, is 0 if there is no Tube or &FF if the Tube system is present.  Only
  332. if the Tube is present may you call the Tube code entry point, as otherwise
  333. it is language workspace eg BASIC's variables.
  334.  
  335. To claim the Tube you must call the Tube code entry point at &0406 with a
  336. reason code of &C0+x in the accumulator. x is an ID code which should
  337. identify you uniquely.  this call return with the carry set if the claim was
  338. successful, carry clear if it failed.  Failure implies that some background
  339. task is using the Tube, so the usual course of action is to keep trying
  340. until yu succeed.  For example, the DFS uses the following subroutine ....
  341. (MASM format)
  342.  
  343. CLATUB PHA            ; Save A, as it happens 
  344. CLATBO LDAIM &C1      ; My magic number
  345.        JSR &0406      ; Tube code entry point
  346.        BCC CLATBO     ; If it failed try again.
  347.        PLA            ; Recover A
  348.        RTS
  349.  
  350. Some other magic numbers which have been allocated are:
  351.  
  352.         &C0 - Cassette filing system
  353.         &C1 - Disc filing system - DFS
  354.         &C2 - Econet - Low level primitives
  355.         &C3 - Econet filing system
  356.         &C4 - ADFS
  357.         &C5 - Teletext
  358.         &C6 - Acorn in-house Terminal - HOSTFS (?)
  359.         &C7 - VFS - video discs
  360.         &C8 - 64/128k beebs sideways RAM utils
  361.         &C9 - Z80 chaps, CP/M
  362.  
  363.         ::
  364.         &CF - Acacia RAM FS (not allocated by us!) - also user applications
  365.  
  366. The ID code is in fact a six bit quantity, so you should use:
  367. LDAIM &CO+MYID
  368. JSR &0406
  369. in your code.
  370.  
  371. When you have finished using the Tube you must release it so that other
  372. users may claim it.  So that another user cannot release the Tube when you
  373. claimed it, you must call the entry point with &80+x in the accumulator,
  374. where x is the same magic number you used when claiming. For example DFS
  375. uses the following subroutines.... (MASM format):
  376.  
  377. RELTUB PHA            ; Save A
  378.        LDAIM &81      ; Magic number
  379.        JSR &0406      ; Tube entry point
  380.        PLA            ; Get A
  381.        RTS
  382.  
  383. 2) Data Transfers/Execution
  384.  
  385. The same entry point is used to initiate a data transfer through the Tube.
  386. The type of transfer is selected by means of a reason code in the
  387. accumulator.  You must also tell the system where in the second processor's
  388. memory space to start the transfer.  You must place the address of te first
  389. byte to the moved (source or destination, depending on the transfer type, or
  390. the Execute address if you are forcing execution in the parasite) in four
  391. bytes of memory in the BBC machine, low byte first as usual, and put the low
  392. byte of the address of these four bytes in X and the high byte of the
  393. address of the four bytes in Y.  So . .
  394.  
  395.         Four byte address in BBC m/c
  396.     YX --->  :     Low byte          :    \
  397.              :     MidLo byte        :     > - - - - - -> data byte in second
  398. processor.
  399.              :     MidHi byte        :   /
  400.              :     Hi byte           :  /
  401.  
  402. Reason codes for data transfers are as follows:
  403.  
  404.         RC      Description                     Initial delay   Delay/ byte
  405.         0       Multi byte transfer, parasite to host   24 uS   24 uS
  406.         1       Multi byte transfer, host to parasite   0       24 uS
  407.                 These transfer any number of bytes in
  408.                 the appropriate direction - terminate by
  409.                 releasing the Tube or recommanding      
  410.                 for another protocol.
  411.  
  412.         2       Multi pairs of bytes transfer, parasite
  413.                 to host                                 26 uS   26 uS/pair
  414.         3       Multi paris of bytes transfer, host to
  415.                 parasite                                 0      26 uS/pair
  416.                 These transfer an even number of bytes
  417.                 in the appropriate direction, faster than
  418.                 protocols 0 and 1 - terminate by
  419.                 releasing the Tube or recommanding
  420.                 for another protocol.
  421.  
  422.         4       Execute - Execution starts in the parasite at
  423.                 the address pointed to by YX.  This call
  424.                 contains an implied release and does not
  425.                 return to you.
  426.  
  427.         5       Reserved - this call is used in handling OS
  428.                 calls which are passed across the Tube.
  429.  
  430.         6       256 byte transfer, parasite to host     19 uS   10 uS/byte
  431.         7       256 byte transfer, host to parasite     0       10 uS/byte
  432.                 These transfer exactly and only 256 bytes
  433.                 only after 256 bytes are transferred may
  434.                 the system be recommanded or released.
  435.  
  436. Having commanded the system, you may now transfer the data. The initial
  437. delay is the time you must wait after control returns to you before you
  438. transfer the first byte of data.  The port used to transfer the data is
  439. memory mapped into the BBC machine at location &FEE5 (another magic number
  440. !), so either do an LDA &FEE5 for parasite to host or STA &FEE5 for host to
  441. parasite to transfer the data.   eg  To transfer 256 bytes of data into an
  442. arbitrary page in the BBC machine memory from the parasite.
  443.  
  444. ; Set up page zero locations &80, &81 to point to the destination page
  445. ; Set up locations &3000, &3001, &3002, &3003 to contain the source address in the parasite
  446.  
  447. CLAIM  LDAIM  &CO+&10           ; Say my ID is 16
  448.        JSR &0406                ; Claim the Tube
  449.        BCC CLAIM
  450.  
  451.        LDXIM &00                ; Lo byte of &3000
  452.        LDYIM &30                ; Hi byte of &3000
  453.        LDAIM 6                  ; P -> H, 256 bytes
  454.        JSR &0406
  455.  
  456.        JSR ANRTS                ; 6 uS delay
  457.        JSR ANRTS                ; 12 uS delay
  458.        JSR ANRTS                ; 18 uS delay
  459.  
  460.        LDYIM 0                  ; so the initial delay in 19 uS
  461.  
  462. LOOP   LDA &FEE5                ; Get it from the port ( 2 uS = 2)
  463.        STAIY &80                ; Put the data byte    (+3 uS = 5)
  464.        NOP                      ;                      (+1 uS = 6)
  465.        NOP                                             (+1 uS = 7)
  466.        NOP                      ;                      (+1 uS = 8)
  467.        INY                      ;                      (+1 uS = 9)
  468.        BNE LOOP                 ; Next data byte       (+1.5 uS = 10.5
  469. uS/byte)
  470.  
  471.        LDAIM &80+&10            ; Release code + My ID
  472.        JSR &0406                ; Release the Tube            
  473.                    :
  474.                    :
  475. ANRTS RTS
  476.  
  477. Execute:
  478. Calling the Tube code with A=4 is used to force execution to start in the
  479. second processor at a location defined by the parasite. This is used by
  480. filing systems when *RUNning a file.  The filing system claims the tube,
  481. loads the program code into the second processor RAM and then uses call 4
  482. with YX pointing to the exec address of the file to start execution of the
  483. code.
  484.  
  485.  
  486. 3) OSWORD calls
  487.  
  488. These are a few things you should know if you are going to use your own
  489. OSWORD calls to pass control/data back and forth across the Tube.
  490.  
  491. Low numbered OSWORD calls:
  492. These have variable numbers of parameters both in and out. In practice, for
  493. all OSWORD calls with A<128, 16 bytes are passed each way.  This covers all
  494. the Acorn assigned calls and allows them to be made transparently from
  495. either side of the Tube.
  496.  
  497. High numbered OSWORD calls:
  498. OSWORD calls with A>128 have a special format to allow a variable number of
  499. parameters to be passed each way.
  500.  
  501. YX ----> n  (byte)
  502. YX+1     m  (byte)
  503. YX+2     data
  504.  
  505. when the call is made in the second processor, n bytes (inclusive of the
  506. bytes containing n and m) are copied into the I/O processor, then the call
  507. is made there with YX pointing to the copy. When the call returns, m bytes
  508. (inclusive again) are copied back into the second processor.  2 <= n,m <=
  509. 128, so you can pass at most 126 bytes of data back and forth.  eg if you
  510. wish to pass a 4 byte record, the first byte of which is a status return,
  511. use:
  512.  
  513. YX  ->  6       ; 6 bytes to the I/O processor
  514.         3       ; 3 bytes returned
  515.         data0
  516.         data1
  517.         data2
  518.         data3
  519.  
  520.  
  521. TUBE AC Electrical Specification (Diagram 1)
  522.  
  523. NB  On the host side, 02 is the timing reference and R/W gives the direction of transfer.  On the parasite side, the timing and direction are implied by MRDS or NWDS.
  524.  
  525.                                                 MIN     MAX
  526.         1)  R/W set up to 02                    35 ns 
  527.         2)  timing strobe pulse width                   110 ns
  528.         3)  address set up time                 35 ns
  529.         4)  address and chip select hold times  10 ns
  530.         5)  data out delay time                         70 ns
  531.         6)  data out hold time                  20 ns
  532.         7)  data in set up time                 50 ns
  533.         8)  data in hold time                   20 ns
  534.         9)  R/W hold time                       10 ns
  535.         10) cycle time                          250 ns
  536.         11) CS set up time                      20 ns
  537.  
  538.         The chip must operate within this specification, as this meets 4MHz
  539. 6502 requirements.
  540.  
  541.         All other timings, such as across tube transfer times, are non
  542. critical, but are expected to be at most 1 or 2 microseconds
  543.  
  544.  
  545. Interrupt Operation
  546.                                                                                                           
  547. The tube has three processor interrupt outputs, two to the parasite (PIRQ &
  548. PNMI) and one to the host (HIRQ).  Each line has an enable bit, and PIRQ has
  549. two, one for each possible interrupt source.  The interrupt lines go active
  550. (low) under the following conditions:
  551.  
  552. HIRQ    Q = 1 and register 4 has data available in the parasite to host latch
  553.  
  554.  
  555. PIRQ    either:  I = 1 and register 1 has data available in the host to
  556. parasite latch
  557.         or:      J = 1 and register 4 has data available in the host to
  558. parasite latch
  559.         (or both)
  560.  
  561. PNMI    either:  M = 1  V = 0  1 or 2 bytes in host to parasite register 3
  562. FIFO or 0 bytes in parasite to host register 3 FIFO (this allows single byte transfers across register 3)
  563.         or:      M = 1  V = 1  2 bytes in host to parasite register 3 FIFO
  564. or 0 bytes in parasite to host register 3 FIFO. (this allows two byte transfers across register 3)
  565.         (or both)
  566.  
  567. In all cases the interrupt condition is cleared by removing the cause; in
  568. the case of HIRQ or PIRQ reading the data from the appropriate register, in
  569. the case of PNMI reading or writing data to or from register 3 as
  570. appropriate.
  571.  
  572. Reset Operation
  573.  
  574. An active (low) signal on HRST initialises the tube to a known state, and
  575. automatically produces a PRST active output to reset the parasite system.
  576.  
  577. The state is T, P, V, M, J, I, Q are all set to zero.
  578.  
  579. All the registers are purged except that register 3 has one valid but
  580. insignificant byte in the parasite to host FIFO (this is to prevent an
  581. immediate PNMI state after PRST).
  582.  
  583. The T control bit allows the processor to reset the Tube to the above state
  584. with the exception that P, V, M, J, I & Q are unaffected, and P allows
  585. separate reset of the parasite processor by the host under software control. 
  586. These resets are activated by setting the respective flags, and they must be
  587. cleared before the reset device will operate again, unless of course HRST is
  588. activated in the mean time.
  589.  
  590. DMA Operation
  591.  
  592. The DRQ pin (active state = 1) may be used to request a DMA transfer - when
  593. M = 1 DRQ will have the opposite value to PNMI, and depends on V in exactly
  594. the sam way (see description of interrupt operation).  DACK then selects
  595. register 3 independently of PAo-2 and PCS, and forces a read cycle if PNWDS
  596. is active or a write cycle if PNRDS is active (not inverse sense of PNWDS
  597. and PNRDS so that the DMA system can read the data from memory an write it
  598. into the Tube in one cycle).
  599.  
  600. Control and Status Flags
  601.  
  602. In the above table the positions in the memory map of the various status and
  603. control bits are shown, and their significance is explained below.
  604.  
  605.         A1, A2, A3, A4 = 1      data available in register 1, 2, 3, 4
  606.         F1, F2, F3, F4 = 1      register 1, 2, 3, 4 not full
  607.         N               =1      register 3 action required (if M = 1 then
  608. PNMI active)
  609.  
  610. The data available flag signifies data available to the processor reading
  611. the flag, whereas the not full flag shows that the register from the
  612. processor reading the flag has space for more data.
  613.  
  614.  
  615. In the case of a simple latch such as register 2, A2 on the host side and F2
  616. on the parasite side will always have the opposite value.  In the case of
  617. the FIFO registers, data is available when there is one of more valid byte
  618. in the register, but the not full flag only becomes inactive when the entire
  619. register is loaded.
  620.  
  621. All registers are simple latches except register 3, which has 2 byte FIFOs
  622. in each direction, and register 1, which has a ten or more byte FIFO from
  623. the parasite to the host.  The host to parasite part of register 1 is a
  624. simple latch.
  625.  
  626.         Q = 1   enable HIRQ from register 4     
  627.         I = 1   enable PIRQ from register 1
  628.         J = 1   enable PIRQ from register 4
  629.         M = 1   enable PNMI from register 3
  630.         V = 1   two byte operation of register 3
  631.         P = 1   activate PRST
  632.         T = 1   clear all Tube registers
  633.         S = 1   set control flag(s) indicated by mask
  634.  
  635. These flags are set or cleared according to the value of S, eg writing 92
  636. (hex) to address 0 will set V and I to 1 but not affect the other flags,
  637. whereas 12 (hex) would clear V and I without changing the other flags.  All
  638. flags except T are read out directly as the least significant 6 bits from
  639. address 0.
  640.  
  641. Register 3 Operation
  642.  
  643. Register 3 is intended to enable high speed transfers of large blocks of
  644. data across the tube.  It can operate in one or two byte mode, depending on
  645. the V flag.  In one byte mode the status bits make each FIFO appear to be a
  646. single byte latch - after one byte is written the register appears to be
  647. full.  In two byte mode the data available flag will only be asserted when
  648. two bytes have been entered, and the not full flag will only be asserted
  649. when both bytes have been removed.  Thus data available going active means
  650. that two bytes are available, but it will remain active until both bytes
  651. have been removed.  Not full going active means that the register is empty,
  652. but it will remain active until both bytes have been entered.  PNMI, N and
  653. DRQ also remain active until the full two byte operation is completed.
  654.  
  655.  
  656. General Description
  657.  
  658. The Tube is a completely asynchronous parallel interface between two
  659. processor systems.  To each system it resembles a conventional peripheral
  660. device, occupying 8 bytes of memory or I/O space.  within that space are
  661. four byte wide read only latches, and four byte wide write only latches,
  662. plus associated control flags.  Some of the latches are just that - data
  663. written in one side is read out of the other on the next read to that
  664. address, but some are in fact FIFO buffers, which store two or more bytes to
  665. be read out in the order they were put in.  Information is stored in the
  666. Tube until removed by the receiving processor, thus allowing completely
  667. asynchronous operation of the two systems.  messages and data are passed to
  668. and fro through the various registers according to carefully designed
  669. software protocols, and proper allocation of the registers to specific tasks
  670. allows both systems to operate with the minimum waiting time.
  671.  
  672.  
  673. Register Organisation 
  674.  
  675. A2    A1    A0    R/W or NWDS     D7    Host          DO  D7  Parasite    DO
  676.  
  677. 0     0     0          1          A1    F1 P V M J I Q    A1  F1 P V M J I Q
  678. 0     0     1          1                read                  read reg 1  (1)
  679. 0     1     0          1          A2    F2 x x x x x x    A2  F2 x x x x x x 0     1     1          1                read reg 2            read reg 2     1     0     0          1          A3    F3 x x x x x x     N  F3 x x x x x x 1     0     1          1                read reg 3    (2)     read reg 3  (3)1     1     0          1          A4    F4 x x x x x x     A4 F4 x x x x x x 1     1     1          1                read reg 4    (4)     read reg 4  (5)  
  680.  
  681. 0     0     0          0           S    T P V M K I Q      x  x x x x x x x
  682. 0     0     1          0                write reg 1   (6)     write reg 1
  683. 0     1     0          0           x    x x x x x x x      x  x x x x x x x 
  684. 0     1     1          0                write reg 2           write reg 2
  685. 1     0     0          0           x    x x x x x x x      x  x x x x x x x
  686. 1     0     1          0                write reg 3   (7)     write reg 3
  687. 1     1     0          0           x    x x x x x x x      x  x x x x x x x
  688. 1     1     1          0                write reg 4   (9)     write reg 4       (10) 
  689.  
  690. Notes:   1) Will clear PIRQ if register 1 was the source
  691.          2) May activate PNMI depending on M and V flags
  692.          3) May clear PNMI (see description of interrupt operation)
  693.          4) Will clear HIRQ if it was active
  694.          5) Will clear PIRQ if register 4 was the source
  695.          6) Will activate PIRQ if I = 1
  696.          7) May activate PNMI depending on M and V flags
  697.          8) May clear PNMI
  698.          9) Will activate PIRQ is J = 1
  699.         10) Will activate HIRQ if Q = 1
  700.         11) All bits marked x are insignificant and will read out as 1
  701.  
  702.  
  703. TUBE Logical Definition (Diagram 2)
  704.  
  705.  
  706. Description of pins:
  707. Power supply    GND             0v reference
  708.                 VCC1            Main +5v supply
  709.                 VCC2            Secondary supply - may not be used. - must
  710. be derived from +5v through dropping resistor.
  711.  
  712. Data buses      HDo-7           8 bit data bus to host processor
  713.                 PD0-7           parasite processor
  714.  
  715. Address signals HAo-2/PAo-2     3 register select lines from host/parasite
  716. address bus
  717.                 HCS/PCS         chip select line from host/parasite addres 
  718. decoding
  719.  
  720. Timing signals  H02             Host processor clock-high level signifies
  721. valid address bus
  722.                 HR/W            Host read-write line-controls direction of
  723. information flow on HDo-7
  724.                 PNRDS           Parasite read strobe (low level active)
  725.                 PNWDS           Parasite write strobe (low level active)
  726.  
  727. Interrupt lines:HRST            Clears all internal latches and initialises
  728. tube to known state - also generates PRST
  729.                 HIRQ            Interrupt to host processor
  730.                 PRST            Reset line to parasite processor
  731.                 PNMI            Non-maskable interrupt to parasite
  732.                 PIRQ            Interrupt to parasite
  733.  
  734. DMA lines       DRQ             Request for DMA transfer
  735.                 DACK            DMA acknowledge from DMA controller
  736.  
  737.  
  738. Schematic diagram of Tube registers (Diagram 3)
  739.  
  740.  
  741. The following tables show the relative address and type of each register in the Tube, firstly for the Host system, and secondly for the parasite system (second processor).
  742.  
  743. Table 1  Host System Registers
  744.  
  745. Address         Read
  746. 000             Status flags and Register 1 flags
  747. 001             Register 1 (24 byte FIFO read only)
  748. 010             Register 2 flags
  749. 011             Register 2 (1 byte read only)
  750. 100             Register 3 flags
  751. 101             Register 3 (2 byte FIFO only)
  752. 110             Register 4 flags
  753. 111             Register 4 (1byte read only)
  754.  
  755. Address         Write
  756. 000             Status flags
  757. 001             Register 1 (1 byte write only)
  758. 010             - - - - - - 
  759. 011             Register 2 (1 byte write only)
  760. 100             - - - - - - 
  761. 101             Register 3 (2 byte FIFO write only)
  762. 110             - - - - - -
  763. 111             Register 4 (1 byte write only)
  764.  
  765. Table 2  Parasite System Registers
  766.  
  767. Address         Read
  768. 000             Status flags and Register 1 flags A1 F1 P V M J I Q
  769. 001             Register 1 (1 byte read only)
  770. 010             Register 2 flags
  771. 011             Register 2 ( 1 byte read only)
  772. 100             Register 3 flags
  773. 101             Register 3 (2 byte FIFO read only)
  774. 110             Register 4 flags
  775. 111             Register 4 (1 byte read only)
  776.  
  777. Address         Write
  778. 000             - - - - - -
  779. 001             Register 1 (24 byte FIFO write only)
  780. 010             - - - - - -
  781. 011             Register 2 (1 byte write only)
  782. 100             - - - - - -
  783. 101             Register 3 (2 byte FIFO write only)
  784. 110             - - - - - -
  785. 111             Register 4 (1 byte write only)
  786.  
  787.  
  788. INTERFACE SPECIFICATION
  789.  
  790.  
  791. Title:          Acorn Tube Software Protocol Specification
  792.  
  793. Reference:      SP0, 989, 900I01
  794.  
  795. Issue No:       08
  796.  
  797. Author:
  798.  
  799. Date:           27. 05. 1986
  800.  
  801. Design Authority:
  802.  
  803.  
  804. NOTE:   All enquiries and requests for changes to this specification must be
  805. directed to the Design Authority.
  806.  
  807. DISTRIBUTION: ACORN   H Fisher        Business Systems Dept
  808.                       A Hinchley      Communication Systems Dept
  809.                       J B Tansley     Engineering Systems Dept
  810.                       M Jenkin        Engineering Systems Dept
  811.                       A McKernan      Personal Systems Dept
  812.                       C B Turner      R & D Services Dept
  813.  
  814.              EXTERNAL F Cockshott     Glasgow Univ.
  815.                       C Hall          TDI
  816.                       J Wein          Digital Research
  817.  
  818.  
  819.         (C)  Copyright Acorn Computers Limited 1986
  820.  
  821.  
  822. Interface Specification         Ref: SOtube8                    
  823.  
  824.  
  825.  
  826. 1  Change History
  827.  
  828. 31 Jan 1984 : Initial issue
  829.  9 Feb 1984 : Correct R4 protocols, Minor clarifications
  830. 24 Feb 1984 : Correct R4 type 0-3 protocols
  831.  6 Aug 1984 : OSWORD Parameter Counts corrected
  832. 12 Oct 1984 : Document restructure
  833. 25 Oct 1984 : Distribution List change
  834. 20 Nov 1984 : Correction of typographical errors
  835. 27 May 1986 : Addition of overview and timing details
  836.  
  837.  
  838. 2  Introduction
  839.  
  840. The Tube allows two processors to communicate using software protocols, it
  841. provides single or multibyte buffering and the handshake signals required.
  842.  
  843. This document describes the Tube protocols from the point of view of the
  844. second processor.  In this document the following conventions are observed:
  845.  
  846.         Hexadecimal numbers are preceded by &
  847.         When bit are numbered within a byte, bit 0 is the least significant
  848. bit
  849.         'Host' refers to the BBC computer
  850.         'Parasite' refers to the second processor
  851.  
  852.  
  853. 3  Overview
  854.  
  855. The objective of a host - parasite tube configuration is to allow the
  856. parasite to execute user programs, using the host system as a servant to
  857. take care of low level I/O tasks.  In order to use the host system as a
  858. servant, the parasite must be able to control suitable routines in the host
  859. system.  The standard host tube code allows the parasite to make use of the
  860. standard BBC operating system calls.  Thus any parasite system, on
  861. initialisation, must be capable of using these standard OS routines through
  862. the tube, and may or may not load new routines into the host at a later
  863. stage of start up.  This document therefore defines the protocols necessary
  864. for making use of these standard OS routines and coping with the results of
  865. issuing commands - for example loading files from disc across the tube into
  866. the parasite system.  a parasite system also has to be able to cope with the
  867. needs of external systems such as a network - which may want to peek or poke
  868. memory in the parasite system.
  869.  
  870. The system calls form three main categories:
  871. a) Calls on which the host system acts and makes no return of information to the parasite.
  872. b) Calls on which the host acts and then returns a few parameters to the
  873. parasite in a non time critical fashion. 
  874. c) Calls on which the host acts and then returns or reads parameters or
  875. blocks of data in time critical fashions. 
  876. An example of category c is a load of a file from disc.  The process is
  877. started by the parasite issuing an appropriate filing system call.  The
  878. filing system response will result in bytes physically read from the disc
  879. having to be passed straight across the tube to the parasite.
  880.  
  881. Categories a and b are dealt with by th host and parasite using registers 1
  882. in the parasite to host direction and 2 in both directions. Register 1 in
  883. the parasite to host direction is used for OSWRCH calls (fitting category
  884. a).  These types of transfer are made by each processor polling the relevant
  885. register status until it reaches the correct state for reading or writing. 
  886. When it is not busy performing tasks, the host processor polls registers
  887. R1STAT and R2STAT, waiting for commands.  Filing system calls (category c)
  888. are made with this type of transfer through register 2, but any time
  889. critical resulting transfer occurs under interrupt.  The 'Non Interrupt
  890. Protocols' section of this document describes in detail the protocols for
  891. these types of transfer,
  892.  
  893. Time critical transfers use registers 1 or 4 in the host to parasite
  894. direction to generate IRQ's in the parasite and reading or writing of
  895. register 3 by the host to generate NMI's in the parasite.  The tube does not
  896. cause interrupts in the host system, nor does the host system poll tube
  897. registers during time critical block transfers such as file loading/saving. 
  898. During time critical block transfers, the host processor simply reads from
  899. or writes to register R3DATA at defined rates.  Each read or write generates
  900. an NMI in the parasite system, and the parasite must service this interrupt
  901. appropriately in time for the next interrupt.  Some transfers also occur
  902. without NMI's through register 3.  The 'Interrupt Driven Operations" section
  903. of this document describes in detail the protocols for these types of
  904. transfer.
  905.  
  906.  
  907. 4  Hardware Structure
  908.  
  909. The Tube hardware provides 4 independent bi-directional communication paths. 
  910. Each consists of a one byte control register and a one byte data register
  911. (which may have multibyte buffering).  The characteristics of each register
  912. set are described below, in the descriptions RnSTAT refers to status
  913. register n and RnDATA refers to its corresponding data register.
  914.  
  915. 4.1  Register set 1
  916.  
  917.         R1DATA
  918.              write
  919.              read (reading clears IRQ)
  920.  
  921.         R1STAT
  922.              bit 7 data available/IRQ
  923.              bit 6 not full
  924.  
  925. In the parasite to host direction this register set is used for the OSWRCH
  926. operating system call.  The data register is a FIFO big enough to enable the
  927. longest VDU command to reside within it - thus increasing the chance that
  928. the host and parasite will achieve parallel execution.
  929.  
  930. In the host to parasite direction the data register provides a 1 byte
  931. buffer.  When the host writes to it an IRQ is generated to the parasite.  It
  932. is used to pass on event interrupts, such as a keypress interrupt, and the
  933. escape operation.
  934.  
  935. 4.2  Register set 2
  936.  
  937.         R2DATA
  938.              write
  939.              read
  940.  
  941.         R2STAT
  942.               bit 7 data available
  943.               bit 6 not full
  944. This register set is used to implement long (in machine time used) OS calls,
  945. or those which (eg RDCH) cannot interrupt the WRCH host background task - in
  946. fact, any call apart from OSWRCH.  The parasite passes a byte to describe
  947. the required action.  The two machines then co-operate in passing data
  948. across R2DATA until the job is done.
  949.  
  950. 4.3  Register set 3
  951.  
  952.         R3DATA
  953.                              write
  954.                              read 
  955.  
  956.         R3STAT
  957.               bit 7 data available/nmi
  958.               bit 6 not full
  959.  
  960. R3DATA is programmable (from the Host) to be either a 1 or 2 byte FIFO.  If
  961. set as a 2 byte FIFO, both bytes have to be written to or read from to cause
  962. or clear a parasite NMI.  Register 3 can be programmed by the host not to
  963. cause parasite NMI's.
  964.  
  965. This register set is used fro the background task of block data transfer
  966. between the two machines (of register set 4).  For higher performance
  967. applications this register may actually interface to a DMA controller.
  968.  
  969. 4.4  Register set 4
  970.  
  971.         R4DATA
  972.              write (writing sets IRQ)
  973.              read (reading clears IRQ)
  974.  
  975.         R4STAT
  976.               bit 7 data available/IRQ
  977.               bit 6 not full/IRQ
  978.  
  979. This register set is used as a control channel for block transfers carried
  980. out across R3.  The host interrupts the second processor by writing a byte
  981. describing the required action into R4DATA.  The two machines then
  982. co-operate in passing data across register 4 until removal of a
  983. synchronisation byte by the parasite signals starting of transfers through
  984. register 3.
  985.  
  986. The register set is also used to initiate the passing of an error string
  987. from host to parasite.  The host interrupts the parasite by writing an error
  988. code into R4DATA, the two machines then cooperate in passing the error
  989. string across R2DATA.
  990.  
  991.  
  992. 5  Software Protocols
  993.  
  994. Notes:
  995. The BBC machine operates by polling the tube register for work.
  996. In all the transactions which may generate errors it is important to realist
  997. that if the error is reported by the BBC machine under interrupt (ie it was
  998. generated by a 6502 BRK sequence), the protocol which generated the error is
  999. abandoned.
  1000.  
  1001. 5.1  Non Interrupt Protocols
  1002.  
  1003. OSWRCH -        Wait until R1DATA not full, write character into R1DATA.
  1004.  
  1005. OSRDCH -        Wait until R2DATA not full, write RDCHNO (=&00) to R2DATA.
  1006.                 Wait for data in R2DATA, top bit of R2DATA is 6502 C@bit
  1007. (validity bit).
  1008.                 Wait for data in R2DATA, R2DATA is 6502 A register
  1009. (character read).
  1010.         
  1011. OSCLI -         Wait until R2DATA not full, write CLINO (=&02) to R2DATA.
  1012.                 FOR all characters in the command string (including
  1013. terminating <cr>)
  1014.                 DO  [
  1015.                      Wait until R2DATA not full, write character to R2DATA
  1016.                     ]
  1017.                 Wait for data in R2DATA and read it.
  1018.  
  1019. IF this byte =&80 then code has been loaded into the second processor store
  1020. as a result of the command and it should be entered at the address given by
  1021. the last R4 protocol type 4 address.
  1022.  
  1023. OSBYTE -         IF osbyteno , &80
  1024.                  THEN [
  1025.                       Wait until R2DATA not full, write SBYTNo (=&04) to
  1026. R2DATA
  1027.                       Wait until R2DATA not full, write parameter for 6502@X
  1028. to R2DATA
  1029.                       Wait until R2DATA not full, write osbyteno to R2DATA
  1030.                       Wait for data in R2DATA, read R2DATA which is 6502@X
  1031. register
  1032.                       ]
  1033.  
  1034.         ELSEIF osbyteno = &82 THEN [ result is machine high order address ]
  1035.         ELSEIF osbyteno = &83 THEN [ result is low memory value ]
  1036.         ELSEIF osbyteno = &84 THEN [ result is high memory value ]
  1037.         ELSE [
  1038.              Wait until R2DATA not full, write BYTENO (=&06) to R2DATA
  1039.              Wait until R2DATA not full, write parameter for 6502@X to
  1040. R2DATA
  1041.              Wait until R2DATA not full, write parameter for 6502@Y to
  1042. R2DATA
  1043.              Wait until R2DATA not full, write osbyteno to R2DATA
  1044.              IF osbyteno=&9D THEN RETURN from protocol (no reply)
  1045.              Wait for data in R2DATA, bit 7 of byte read is from 6502@C
  1046.              Wait for data in R2DATA, byte read is 6502@Y
  1047.              Wait for data in R2DATA, byte read is 6502@X
  1048.              ]
  1049.  
  1050. OSWORD -     IF oswordno = &00
  1051.              THEN [ ; Doing readline
  1052.                   Wait until R2DATA not full, write RDLNNO (=&0A) to R2DATA
  1053.                   Wait until R2DATA not full, write upper bound char to
  1054. R2DATA
  1055.                   Wait until R2DATA not full, write lower bound char to
  1056. R2DATA
  1057.                   Wait until R2DATA not full, write length allowed to R2DATA
  1058.                   Wait until R2DATA not full, write &07 to R2DATA
  1059.                   Wait until R2DATA not full, write &00 to R2DATA
  1060.                   Wait for data in register2 -> response
  1061.                   IF response .&7F
  1062.                   THEN [
  1063.                         ; escape was pressed on input
  1064.                         RETURN from protocol
  1065.                        ]
  1066.                   Read a <cr> terminated string from R2DATA
  1067.                   ]
  1068.              ELSE [
  1069.                   Wait until R2DATA not full, write WORDNO (=&08) to R2DATA
  1070.                   Wait until R2DATA not full, write oswordno to R2DATA
  1071.                   Wait until R2DATA not full, write #params to send to
  1072. R2DATA
  1073.                   Write parameter block to R2DATA, last byte first
  1074.                   Wait until R2DATA not full, write #params to recv to
  1075. R2DATA
  1076.                   Read bytes back from R2DATA into parameter block, last
  1077. byte first
  1078.                   ]
  1079.  
  1080. The number of parameters to send/receive is determined by:
  1081. IF oswordno<&14
  1082. THEN [         Determine number of parameters from following tables
  1083.  
  1084.  OSWORD number   Parameters to send     Parameters to receive
  1085.         1               0                          5
  1086.         2               5                          0
  1087.         3               0                          5
  1088.         4               5                          0
  1089.         5               2                          5
  1090.         6               5                          0
  1091.         7               8                          0
  1092.         8              14                          0
  1093.         9               4                          5
  1094.         10              1                          9
  1095.         11              1                          5
  1096.         12              5                          0
  1097.         13              0                          8
  1098.         14             16                         16
  1099.         15             16                         16
  1100.         16             16                         13
  1101.         17             13                         13
  1102.         18              0                        128
  1103.         19              8                          8
  1104.         20            128                        128
  1105.  
  1106.              ]
  1107. ELSEIF oswordno <&80
  1108. THEN  [
  1109.          # parameters to send=16
  1110.          # parameters to receive=16
  1111.       ] 
  1112. ELSE  [
  1113.           # parameters determined in call specific manner
  1114.              (eg by embedding in transfer block)
  1115.       ]
  1116.  
  1117. OSBPUT -        Wait until R2DATA not full, write BPUTNO (=&10) to R2DATA
  1118.                 Wait until R2DATA not full, Y to R2DATA (file handle)
  1119.                 Wait until R2DATA not full, A to R2DATA (byte to write)
  1120.                 Wait for data from R2DATA, discard it
  1121.  
  1122. OSBGET -        Wait until R2DATA not full, write BGETNO (=&0E) to R2DATA
  1123.                 Wait until R2DATA not full, write file handle to R2DATA
  1124.                 Wait for data in R2DATA, top bit of byte is 6502@C (validity
  1125. bit)
  1126.                 Wait for data in R2DATA, read R2DATA which is byte read from
  1127. file
  1128.  
  1129. OSFIND -        Wait until R2DATA not full, write FINDNO (=&12) to R2DATA
  1130.                 Wait until R2DATA not full, write type of open to R2DATA
  1131.                 IF type=0
  1132.                 THEN [
  1133.                      Wait until R2DATA not full, write file handle to R2DATA
  1134.                      Wait for data in R2DATA, read result
  1135.                      ]
  1136.                 ELSE [
  1137.                      Wait until R2DATA not full, write file name string to
  1138. R2DATA (including terminating <cr>)
  1139.                      Wait for data in R2DATA, read handle from R2DATA
  1140.                      ]
  1141.  
  1142. OSARGS -        Wait until R2DATA not full, write ARGSNO (=&0C) to R2DATA
  1143.                 Wait until R2DATA not full, write file handle to R2DATA
  1144.                 Waiting for R2DATA not full,
  1145.                 [ write 4 bytes orsarg@data to R2DATA (ms byte first) ]
  1146.                 Wait until R2DATA not full, write operation code to R2DATA
  1147.                 Wait for data in R2DATA, read fs type from R2DATA
  1148.                 Waiting for R2DATA data,
  1149.                 [ read 4 bytes osarg@data from R2DATA (ms byte first) ]
  1150.  
  1151. Note:  osarg@data is the file sequential pointer or length depending on the
  1152. type of OSARG call.
  1153.  
  1154. OSFILE -        Wait until R2DATA not full, write FILENO (=&14) to R2DATA
  1155.                 Waiting for R2DATA not full,
  1156.                 [ write 16 byte OSFILE control block to R2DATA ]
  1157.                         (last byte of block is written first)
  1158.                 Waiting for R2DATA not full, write filename to R2DATA
  1159. including terminating <cr>
  1160.                 Wait until R2DATA not full, write type of transfer to R2DATA
  1161.                 (Any transfer is completed under interrupt using R3, R4)
  1162.                 Wait for data in R2DATA, read R2DATA AND &7F = filing system
  1163. type
  1164.                 Waiting for data in R2DATA,
  1165.                 [ read back 16 byte control block from R2DATA ]
  1166.                         (last byte of block is read first)
  1167.  
  1168.  
  1169. Note:  The 16 byte control block has format as shown in Diagram 4.
  1170.               
  1171.  
  1172. OSGBPB -        Wait until R2DATA not full, write GBPBNO (=&16) to R2DATA
  1173.                 Wait until R2DATA not full,
  1174.                      [ write 13 byte OSGBPB control block to R2DATA ]
  1175.                         (last byte of block is written first)
  1176.                 Wait until R2DATA not full, write type of transfer to R2DATA
  1177.                 Waiting for data in R2DATA
  1178.                      [ read back 13 byte control block from R2DATA ]
  1179.                         (last byte of clock is read first)
  1180.                 Wait for data in R2DATA, read R2DATA bit 7 is 6502@C bit
  1181.                 Waiting for data in R2DATA, read 6502@A from R2DATA
  1182.  
  1183.  
  1184. 5.2  Interrupt driven operations
  1185.  
  1186. In addition to these parasite initiated activities the parasite is also
  1187. required to respond to interrupts from registers 1, 3 and 4.
  1188.  
  1189. To determine the source of an interrupt it is important to follow the
  1190. following order:
  1191.  
  1192.         1.  check for register 4 interrupt
  1193.         2.  check for register 1 interrupt
  1194.  
  1195. Register 1 interrupts:
  1196.  
  1197. Register 1 interrupts occur only in the host to parasite direction.  The
  1198. interrupt service sequence is:
  1199.  
  1200.         Read type byte from R1DATA IF type <0 THEN
  1201.                  [; escape flag update
  1202.                    Replace the escape flag with bit 6 of type
  1203.                    RETURN from servicing interrupt
  1204.                  ] ELSE
  1205.                  [; Event signal
  1206.                    Interrupt@R1@read 6502@Y event parameter
  1207.                                   Interrupt@R1@read 6502@X event parameter
  1208.                    Interrupt@R1@read 6502@A event parameter
  1209.                   ; BBC machine will now continue processing
  1210.                   ; any other actions to service event can be taken
  1211.                  ]
  1212.  
  1213. Where Interrupt@R1@read is:
  1214.     UNTIL data@ready@in@R1
  1215.     DO  [
  1216.          IF data@ready@in@R4 THEN CALL R4@interrupt@service
  1217.         ]
  1218.     RETURN read R1DATA
  1219.  
  1220.  
  1221. Register 4 Interrupts:
  1222.  
  1223. Read type byte from R4DATA IF type<0
  1224.     THEN [; BBC machine is reporting an error
  1225.             Wait for data in R2DATA, read and discard it
  1226.             Wait for data in R2DATA, read error number form R2DATA
  1227.             Read a zero byte terminated string from R2DATA
  1228.          ]
  1229.      ELSE
  1230.          [; Type is a command to initialise for register 3 block transfer
  1231.             Wait for data in register 4, read Claimer@identity* from R4DATA
  1232.  
  1233. * For details of the identity numbers see Appendix A
  1234.  
  1235.           CASE type OF
  1236.           [
  1237.            0  :  ; Single byte transfer parasite to host.
  1238.                  Read 4 byte base address for transfer from R4DATA msb first
  1239.                  Set NMI routine for this transfer type
  1240.                  Wait for and remove synchronising byte from R4DATA
  1241.  
  1242.            1  :  ; Single byte transfer host to parasite
  1243.                  Read 4 byte base address for transfer from R4DATA msb first
  1244.                  Set NMI routine for this transfer type
  1245.                  Wait for and remove synchronising byte from R4DATA
  1246.  
  1247.            2  :  ; Double byte transfer parasite to host
  1248.                  Read 4 byte base address for transfer from R4DATA msb first
  1249.                  Set NMI routine for this transfer type
  1250.                  Wait for and remove synchronising byte from R4DATA
  1251.  
  1252.            3  :  ; Double byte transfer host to parasite
  1253.                  Read 4 byte base address for transfer from R4DATA msb first
  1254.                  Set NMI routine for this transfer type
  1255.                  Wait for and remove synchronising byte from R4DATA
  1256.  
  1257.            4  :  ; No transfer (pass address host to parasite only)
  1258.                  Read 4 byte address from R4DATA msb first
  1259.                  Wait for data in R4DATA, discard it
  1260.  
  1261.            5  :  ; No transfer (filing system release)
  1262.  
  1263.            6  :  ; 256 type transfer parasite to host without interrupt
  1264.                  Read 4 byte base address for transfer from R4DATA msb first
  1265.                  Wait for data in Register 4, discard it
  1266.                  Transfer 256 bytes to host, via R3DATA
  1267.                  Write a byte into R4DATA; To stop unwanted ints on host
  1268.  
  1269.            7  :  ; 256 byte transfer host to parasite without interrupt
  1270.                  Read 4 byte base address for transfer from R4DATA msb first
  1271.                  Wait for data in Register 4, discard it
  1272.                  Transfer 256 bytes from host via R3DATA
  1273.           ]
  1274.           RETURN ; From the interrupt
  1275.  
  1276. Notes:
  1277.  
  1278. For types 0-3:  As soon as the synchronising byte is remove register 3
  1279. transfer requests (NMI's) will start to occur.  When the interrupt occurs 1
  1280. or 2 bytes are transferred (depending on the current mode).
  1281.  
  1282. A release (type 5) is a guarantee that no more register 3 NMI's will occur
  1283. for the current transfer.
  1284.  
  1285.  
  1286. Register 3 Transfer Timings  
  1287.                 
  1288. During such an operation as loading a file into the parasite system from
  1289. disc, data has to be rapidly passed through the tube at instants dictated by
  1290. a physical process - in this case, reading from a disc.  For this reason
  1291. such transfers are made via register 3, which may be programmed to cause
  1292. parasite NMI's.  Because these NMI's occur very rapidly, there are
  1293. constraints on the timings with which the parasite must respond to such
  1294. NMI's.
  1295.  
  1296. After the parasite processor has read the synchronisation byte from register
  1297. 4, the host processor will wait for at least the length of the initial delay
  1298. below (zero for host to parasite direction) before transferring the first
  1299. byte of data.  Thus for transfers in the parasite to host direction, this
  1300. initial delay is the time within which the parasite must place the fist byte
  1301. (or pair of bytes) of data in register 3 after removing the synchronising
  1302. byte.  For NMI transfers in the host to parasite direction, this delay is
  1303. zero - the parasite processor must be ready to cope with register 3 NMI's as
  1304. soon as it has removed the synchronisation byte from register 4.  For type 7
  1305. transfer, not using NMi's the host will write the first byte without delay,
  1306. but the parasite cannot receive a byte immediately from R3DATA as it has to
  1307. test the data available bit in R3STAT.  The parasite has to read this first
  1308. byte in R3DATA before it is overwritten by the next host write.  Assuming
  1309. the host code is as below, this allows 15.5 uS to read the first byte:
  1310.  
  1311.         JSR     &406    ;  Initialise tube - routine returning when parasite
  1312. reads
  1313.                         ;  synchronising byte
  1314.         LDY     0       ;  1 uS
  1315. .loop   LDA     (host), Y       ;  2.5 uS
  1316.         STA     TPORT   ;  2 uS
  1317.         NOP             ;  1 uS
  1318.         NOP             ;  1 uS
  1319.         NOP             ;  1 uS
  1320.         INY             ;  1 uS
  1321.         BNE     loop    ;  1.5 uS
  1322.  
  1323. (1 + 2.5 + 2 + 1 + 1 + 1 + 1 + 1.5 + 2.5 + 2 = 15.5)
  1324.  
  1325. The service time is the maximum time that the parasite has to process each
  1326. subsequent transfer.  The host code is a simple loop reading or writing
  1327. data, and so the parasite must be capable of inputting or outputting data
  1328. fast enough for this loop.  For transfers of type 1 to 3, the host writing
  1329. to or reading from register 3 a byte (or pair of bytes) causes an NMI in the
  1330. parasite.  thus the service time is an upper bound on the allowed time for
  1331. te NMI service routine.  Similarly, for type 6 and 7 transfers, the service
  1332. time is the maximum time for the parasite to transfer each byte to or from
  1333. R3DATA.
  1334.  
  1335. Transfer type           Transfer direction      Initial delay   Service time
  1336.          0                      P to H               24 uS         24 uS
  1337.          1                      H to P                0 uS         24 uS
  1338.          2                      P to H               26 uS         26 uS/pair
  1339.          3                      H to P                0 uS         25 uS/pair
  1340.          6                      P to H               19 uS         10 uS
  1341.          7                      H to P                0 uS         10 uS
  1342.  
  1343.  
  1344.  
  1345. 6  Startup Protocol
  1346.  
  1347. The Startup sequence for the second processor is:
  1348.  
  1349.         Use the OSWRCH mechanism to write out a startup message
  1350.         Send a zero byte to host via R1DATA to terminate it
  1351.         Wait for data in R2DATA
  1352.         ;  during this wait a load may occur from the host
  1353.         ;  using R4/R3 block transfer protocols
  1354.         IF data=&80 THEN execute from the address given in the R4 type 4
  1355. transfer
  1356.  
  1357.  
  1358. APPENDIX A:  Filing System Claimer Identities
  1359.  
  1360. When a filing system claims the R3/R4 resource in the host its identity is
  1361. passed to the second processor as part of the R4 startup protocol.  The
  1362. identity codes are not related to filing system numbers.
  1363.  
  1364.         Filing System                  Claim Identity Used
  1365.  
  1366.         Tape                                     0                        
  1367.         DFS                                      1
  1368.         NFS                                      2
  1369.         NFS                                      3
  1370.         ADFS                                     4
  1371.